package dao;

import db.DB;
import vo.Users;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao implements IUserDao {
    @Override
    public boolean login(Users u) throws SQLException {
        boolean b=false;
        DB db=new DB();
        Connection connection=db.getConn();
        PreparedStatement ps=connection.prepareStatement("select * from user where username=? and password=?");

        ps.setString(1,u.getUsername());
        ps.setString(2,u.getPassword());
        ResultSet rs=ps.executeQuery();
        b=rs.next();


        return b;
    }

    public static void main(String[] args){
        UserDao dao=new UserDao();
        Users users=new Users();
        users.setUsername("admin");
        users.setPassword("123456");
        try {
            System.out.print(dao.login(users));
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
